package visao;

import conexao.ConectEvent;
import java.awt.Color;
import javax.swing.JOptionPane;
import util.DAOEvent;

public class CadPreferencias extends DialogAbstrato {
  /*Classe responsavel pelo cadastro ou edição do professor
  ela é instanciada apartir da ação do obj btProfessor ou do novoProfessor
  na classe SadGui*/

  public CadPreferencias(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    this.setLocationRelativeTo(parent);
  }

  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        saveProfessor = new javax.swing.JPanel();
        txtIDServ = new javax.swing.JTextField();
        txtPorta = new javax.swing.JTextField();
        lblIDServ = new javax.swing.JLabel();
        lblPorta = new javax.swing.JLabel();
        lblMessage = new javax.swing.JLabel();
        btnAlterar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SAD - Cadastro");

        saveProfessor.setBorder(javax.swing.BorderFactory.createTitledBorder("Preferencias"));

        txtIDServ.setFocusCycleRoot(true);
        txtIDServ.setFocusTraversalPolicyProvider(true);

        txtPorta.setFocusTraversalPolicyProvider(true);

        lblIDServ.setText("ID do Servidor:");

        lblPorta.setText("Porta:");

        javax.swing.GroupLayout saveProfessorLayout = new javax.swing.GroupLayout(saveProfessor);
        saveProfessor.setLayout(saveProfessorLayout);
        saveProfessorLayout.setHorizontalGroup(
            saveProfessorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(saveProfessorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(saveProfessorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(saveProfessorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(lblPorta)
                        .addComponent(txtPorta, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                        .addComponent(lblIDServ)
                        .addComponent(txtIDServ))
                    .addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
                .addContainerGap())
        );
        saveProfessorLayout.setVerticalGroup(
            saveProfessorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, saveProfessorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblIDServ)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtIDServ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lblPorta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtPorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(88, 88, 88))
        );

        btnAlterar.setText("Alterar");
        btnAlterar.setActionCommand("Alterar");

        btnCancelar.setText("Cancelar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(saveProfessor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(btnAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(saveProfessor, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JLabel lblIDServ;
    private javax.swing.JLabel lblMessage;
    private javax.swing.JLabel lblPorta;
    private javax.swing.JPanel saveProfessor;
    private javax.swing.JTextField txtIDServ;
    private javax.swing.JTextField txtPorta;
    // End of variables declaration//GEN-END:variables

  // <editor-fold defaultstate="collapsed" desc="Responde a eventos da Conexao">
  @Override
  public void modelConectChange(ConectEvent evt) {
    switch (evt.getID()) {
      case ConectEvent.CONECTADO:
        this.close();
        break;
      case ConectEvent.ERRO_CONEXAO:
        lblMessage.setForeground(Color.RED);
        lblMessage.setText(evt.getMSG());
        break;
    }
  }// </editor-fold>

  // <editor-fold defaultstate="collapsed" desc="Retorna dados do objeto">
  public String getIDServ() {
    return this.txtIDServ.getText();
  }

  public String getPorta() {
    return this.txtPorta.getText();
  }// </editor-fold>

  //<editor-fold defaultstate="collapsed" desc="Métodos públicos comuns a todos os Dialogs">
  @Override
  public void addOuvintes() {
    btnAlterar.addActionListener(getSuporteEventos());
    btnCancelar.addActionListener(getSuporteEventos());
    this.addWindowOuvinte(getSuporteEventos());
  }

  @Override
  public void close() {
    this.resetDialog();
    this.dispose();
  }

  @Override
  public void setEditableDados(Object[] o) {
    if (o != null) {
      btnAlterar.setText(o[0].toString());
    }
  }//</editor-fold>

  //<editor-fold defaultstate="collapsed" desc="Métodos privados, mas comuns a todos os Dialogs">
  @Override
  protected void resetDialog() {
    txtIDServ.setText(null);
    txtPorta.setText(null);
    lblMessage.setText(null);
    txtIDServ.requestFocusInWindow();
  }

  @Override
  protected void focusField(String field) {
    if (field.equals("IDServ")) {
      txtIDServ.requestFocusInWindow();
    } else if (field.equals("Porta")) {
      txtPorta.requestFocusInWindow();
    }
  }//</editor-fold>
}
